package genetic;

import genetic.treenodes.Addition;
import genetic.treenodes.Division;
import genetic.treenodes.Multiplication;
import genetic.treenodes.Subtraction;
import genetic.treenodes.Variable;
import genetic.treevisualizer.METreeBranchRenderer;
import genetic.treevisualizer.METreeNodeRenderer;
import genetic.treevisualizer.TreeVisualizer;

import java.io.File;
import java.util.ArrayList;

import org.jfree.data.xy.XYSeriesCollection;

@SuppressWarnings("unused")
public class T07_inputDataWithGP {

	private XYSeriesCollection dataSeries = new XYSeriesCollection();
	private ArrayList<DataSet> dataSets = null;

	public T07_inputDataWithGP() {
		TreeVisualizer tv = new TreeVisualizer();
		tv.setTreeBranchRenderer(new METreeBranchRenderer());
		tv.setTreeNodeRenderer(new METreeNodeRenderer());
		
		ArrayList<GPTreeNode> functionSet = new ArrayList<GPTreeNode>();
		ArrayList<GPTreeNode> terminalSet = new ArrayList<GPTreeNode>();
		
		functionSet.add(new Addition());
		//functionSet.add(new Subtraction());
		//functionSet.add(new Multiplication());
		//functionSet.add(new Division());

		terminalSet.add(new Variable("x"));
//		terminalSet.add(new Constant(22.22));
		
		dataSeries.addSeries(GPApplication.loadFromExcel("test.xls", "x"));
		dataSets = DataSet.createListFromXYSeriesCollection(dataSeries);
		
		GeneticProgram gp = new GeneticProgram(functionSet, terminalSet);
		gp.createRandom(3, 1);
		

		tv.writeImageFile(tv.renderTree(gp.getRoot()), new File("T06_inputDataWithGP.png"));
		
		for (DataSet ds : dataSets) {
			System.out.println(gp.evaluate(ds));
		}
	}
	
	public static void main(String[] args) {
		
		new T07_inputDataWithGP();
		
		
	}
}
